package com.example.newdemo.view.recyclerView.scale;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.newdemo.BaseActivity;
import com.example.newdemo.R;
import com.example.newdemo.tv.RecyclerViewTV;
import com.example.newdemo.utils.LogUtils;

public class ScaleRecyclerViewDemoActivity extends BaseActivity {
    @Override
    protected int getLayoutId() {
        return R.layout.scale_recycler_view_demo_act;
    }

    @Override
    protected void initView() {

        RecyclerViewTV recyclerView =  findViewById(R.id.scale_recycler_view_demo);

        GridLayoutManager manager = new GridLayoutManager(ScaleRecyclerViewDemoActivity.this, 1);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        manager.supportsPredictiveItemAnimations();
        recyclerView.setLayoutManager(manager);

        int itemSpace = getResources().getDimensionPixelSize(R.dimen.dp_52);
        recyclerView.addItemDecoration(new SpaceItemDecoration(itemSpace));

        final MyAdapter mAdapter = new MyAdapter(ScaleRecyclerViewDemoActivity.this);
        recyclerView.setAdapter(mAdapter);

        recyclerView.setFocusable(false);
        recyclerView.setSelectedItemAtCentered(true); // 设置item在中间移动.


        recyclerView.setOnItemListener(new RecyclerViewTV.OnItemListener() {
            @Override
            public void onItemPreSelected(RecyclerViewTV parent, View itemView, int position) {
                LogUtils.d(" 失去焦点 ** onItemPreSelected   postion = " + position);
            }

            @Override
            public void onItemSelected(RecyclerViewTV parent, View itemView, int position) {
                LogUtils.d(" 获得  -- onItemSelected   postion = " + position);
            }

            @Override
            public void onReviseFocusFollow(RecyclerViewTV parent, View itemView, int position) {
                LogUtils.d("修改  /// onReviseFocusFollow   postion = " + position);
            }
        });

        recyclerView.setOnItemClickListener(new RecyclerViewTV.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerViewTV parent, View itemView, int position) {
                LogUtils.d("--点击----- position = " + position);
            }
        });




    }

    @Override
    protected void initData() {

    }

    private class SpaceItemDecoration extends RecyclerView.ItemDecoration {
        private int space;
        SpaceItemDecoration(int space) {
            this.space = space;
        }

        @Override
        public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
            outRect.left = space;
        }
    }
}
